package com.byq.ai.agentlab.po;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;

import java.util.ArrayList;
import java.util.List;

public class Conversation {
    String id;

    public void setId(String id) {
        this.id = id;
    }



    public List<Message> getMessages() {
        return messages;
    }

    public void setMessages(List<Message> messages) {
        this.messages = messages;
    }

    public String getId() {
        return id;
    }



    List<Message> messages = new ArrayList<>();

    public Conversation(String c) {
        this.id = c;
    }

    static public void main(String[] args){
        ObjectMapper objectMapper = new ObjectMapper();

        // 创建示例对象
        List<Message> ms = new ArrayList<>();
        SystemMessage sm = new SystemMessage("mmm");
        ms.add(sm);

        try {
            // 1. 序列化（对象转 JSON 字符串）
            String jsonString = objectMapper.writeValueAsString(ms);
            System.out.println("序列化结果: " + jsonString);

            // 2. 反序列化（JSON 字符串转对象）
            Conversation deserializedPerson = objectMapper.readValue(jsonString, objectMapper.getTypeFactory().constructCollectionType(List.class, Message.class));
            System.out.println("反序列化结果: " + deserializedPerson);

            // 3. 从文件读取并反序列化（示例）
            // Person fromFile = objectMapper.readValue(new File("person.json"), Person.class);

            // 4. 将对象写入文件（示例）
            // objectMapper.writeValue(new File("person.json"), person);

        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
    }



}
